#!/usr/bin/env python
#coding=UTF-8

from KeyboardKeys import key as keys
from pygame import *

def get_key(azerty, events):
    mods = key.get_mods()
    caps = mods & (KMOD_SHIFT | KMOD_CAPS)
    altgr = mods & ((KMOD_LCTRL & KMOD_LALT) | KMOD_RALT)
    
    for e in events:
        if e.type == KEYDOWN:
            if azerty:
                if caps:
                    return keys[e.key][1][1]
                elif altgr:
                    return keys[e.key][1][2]
                else:
                    return keys[e.key][1][0]
            else:
                if caps:
                    return keys[e.key][0][1]
                elif altgr:
                    return keys[e.key][0][2]
                else:
                    return keys[e.key][0][0]
    return None
    